/*
 * Copyright (C) 2014 Nathan Templon
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package unit;

import java.util.Objects;

/**
 *
 * @author Nathan Templon
 */


public class UnitType implements Comparable {
    
    public UnitType( String type ) {
        this.typeName = type.toUpperCase();
    }
    
    
    public String name() {
        return typeName;
    }
    
    
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof UnitType)) {
            return false;
        }
        else {
            UnitType otherType = (UnitType)o;
            return (otherType.name().equals(typeName));
        }
    }

    
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 67 * hash + Objects.hashCode(this.typeName);
        return hash;
    }
    
    
    private final String typeName;

    @Override
    public int compareTo(Object o) {
        // The position that we are relative to the provided object
        final int BEFORE = -1;
        final int EQUAL = 0;
        final int AFTER = 1;
        
        if (this.equals(o)) {
            return EQUAL;
        }
        
        if (o instanceof UnitType) {
            UnitType newO = (UnitType)o;
            return this.name().compareTo(newO.name());
        }
        
        // If they didn't send us a UnitType, there isn't much else we can do
        return EQUAL;
    }
    
}
